package ${packageName}.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import ${applicationPackage}.R;
import ${applicationPackage}.BR;
import ${applicationPackage}.databinding.ActivityBasePagerBinding;
import ${packageName}.adapter.BaseFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseViewModel;


public abstract class BasePagerActivity extends BaseActivity<ActivityBasePagerBinding, BaseViewModel> {
  
    protected List<Fragment> mFragments = new ArrayList<>();
    protected List<String> titlePager = new ArrayList<>();

    protected abstract List<Fragment> pagerFragment();

    protected abstract List<String> pagerTitleString();

    @Override
    public int initContentView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_base_pager;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        mFragments = pagerFragment();
        titlePager = pagerTitleString();
        //设置Adapter
        //BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), mFragments, titlePager);
        BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titlePager);
        binding.viewPager.setAdapter(pagerAdapter);
        binding.tabs.setupWithViewPager(binding.viewPager);
        binding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabs));
        initView( binding.viewPager, binding.tabs);
    }

    protected abstract void initView(ViewPager viewPager, TabLayout tabs);

    @Override
    public void initViewObservable() {

    }
}
